// pages/Main/mainIndex/mainIndex.js
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var common = require('../../../utils/common.js')

Page({

  /**
   * 页面的初始数据
   */

  data: {
    title: '',
    testList: [],
    ur:'',
    num: 1,
    scrollHeight: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = common.Getorgid();
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });
    this.setData({
      orgid: c.orgid,
      userid: c.userid,
      scrollHeight: scrollHeight,
    });
    this.QueryGrade();
  },
  /* testDetail: function (e) {
    wx.navigateTo({
      url: "../answeron/answeron?title='试卷详情'&&remarktype=4&&examtype='1'&&examid=''&&parid=" + e.currentTarget.dataset.id
    });
  },  */stuTestview: function (event) {
    wx.navigateTo({
      url: "../stuTestview/stuTestview?title=试卷详情&&remarktype=4&&examid=''&&parid=" + event.currentTarget.dataset.id + "&&biaoti=试卷管理总览"
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.ConditionList = this.selectComponent("#ConditionList");
    this.ConditionList.close();
    this.shanxuan();
  },
  isShow: function (e) {
    this.ConditionList.isShow();
    this.QueryGrade();
  },
  //筛选
  shanxuan: function (ur) {
    if (ur == '' || ur == undefined) {
      var ur = '';
      let params = { classid: "b981a439-e563-4114-8cae-5346ac7bfe52", "orgid": this.data.orgid, "ur": ur }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.ConditionList.conditionList(res, ur);
      })
    } else {
      console.log(ur.detail)
      let params = { classid: "b981a439-e563-4114-8cae-5346ac7bfe52", "orgid": this.data.orgid, "ur": ur.detail[0] }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.setData({
          ur: ur.detail[0]
        })
        this.ConditionList.conditionList(res, ur.detail[0]);

      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      this.QueryGrade();
    } else {
      common.showToast("到底了", "loading");
    }
  },
  QueryGrade: function () {
    common.showLoading("加载中", "loading");
    let params = { "page": this.data.num, "num": 15, "orgid": this.data.orgid, "userid": this.data.userid, "ur": this.data.ur, "searchField": "addpeopleid,title", "searchValue": this.data.userid + "," + this.data.title }
    businessLogic.QueryGrade(params, (res) => {
      //console.log(params)
      // console.log(res);
      var page = res.page
      var res = res.infos;
      for (let a = 0; a < res.length; a++) {
        var x = []
        switch (res[a].subject_dictionary_title) {
          case "语文":
            x = "yuwen"
            break;
          case "数学":
            x = "shuxue"
            break;
          case "英语":
            x = "english"
            break;
          case "物理":
            x = "wuli"
            break;
          case "化学":
            x = "huaxue"
            break;
          case "政治":
            x = "zhengzhi"
            break;

          default:
            x = "zhengzhi";
        }
        res[a].color = [];
        res[a].color.push(x);

      }
      var bbb = this.data.testList
      for (var a = 0; a < res.length; a++) {
        bbb.push(res[a]);
      }

      this.setData({
        testList: bbb,
        lenpage: page.pages
      });
      common.hideLoading();
    });
  },
  bindKeyInput: function (e) {
    this.setData({
      title: e.detail.value
    })
  },
  search2: function (event) {
    common.showLoading("加载中", "loading");
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "ur": this.data.ur, "searchField": "addpeopleid,title", "searchValue": this.data.userid + "," + this.data.title }
    businessLogic.QueryGrade(params, (res) => {
      var res = res.infos;
      for (let a = 0; a < res.length; a++) {
        var x = []
        switch (res[a].subject_dictionary_title) {
          case "语文":
            x = "yuwen"
            break;
          case "数学":
            x = "shuxue"
            break;
          case "英语":
            x = "english"
            break;
          case "物理":
            x = "wuli"
            break;
          case "化学":
            x = "huaxue"
            break;
          case "政治":
            x = "zhengzhi"
            break;

          default:
            x = "zhengzhi";
        }
        res[a].color = [];
        res[a].color.push(x);

      }
      this.setData({
        testList: res
      });
      common.hideLoading();
    });
  },
})